home *** CD-ROM | disk | FTP | other *** search
/ NetNews Offline 2 / NetNews Offline Volume 2.iso / news / comp / lang / c-part2 / 15482 < prev    next >
Encoding:
Text File  |  1996-08-05  |  1.1 KB  |  59 lines

  1. Path: noc.netcom.net!news
  2. From: Tarang Deshpande <tarang@willows.com>
  3. Newsgroups: comp.lang.c
  4. Subject: Re: ===  **ptr  HELP  ===
  5. Date: Thu, 18 Apr 1996 12:07:14 -0700
  6. Organization: NETCOM Network Operations
  7. Message-ID: <317692E2.6D0F@willows.com>
  8. References: <31765AA6.41C6@cell.co.uk>
  9. NNTP-Posting-Host: daffy.willows.com
  10. Mime-Version: 1.0
  11. Content-Type: text/plain; charset=us-ascii
  12. Content-Transfer-Encoding: 7bit
  13. X-Mailer: Mozilla 2.0GoldB2 (Win95; I)
  14.  
  15. Kai Chan wrote:
  16. > main()
  17. > {
  18. >         some_type1      **ptr;
  19. >         func1(ptr);     /* is this right? */
  20. >         func1(&ptr);    /* or this? */
  21. >         func1(**ptr);   /* or this? */
  22. >         func1(*ptr);    /* or this? */
  23. > }
  24. > func1(some_type1 **ptr)
  25. > {
  26. >         blar...
  27. >         blar...
  28. > }
  29.  
  30.  
  31. Technically func1(ptr) is right.  However I'm not sure that it's really
  32. what you want to do.  If what you want to do is to have a function assign
  33. the pointer then what you really want is:
  34.  
  35. int func1 ( void **p, int x )
  36. {
  37.     if ( *p = malloc ( x ) )
  38.         return ( x );
  39.     else
  40.         return ( 0 );
  41. }
  42.  
  43. int main ( void )
  44. {
  45.  
  46.     void    *p;
  47.  
  48.     if ( func1 ( &p, 10 ) )
  49.         free ( p );
  50.  
  51.     return ( 0 );
  52.  
  53. }
  54.